<?php
/**
 * Created by PhpStorm.
 * User: fengsenhua
 * Date: 2019/2/10
 * Time: 20:52
 */

namespace app\api\controller\v1;


use app\api\validate\IDColllection;
use app\api\model\Theme as ThemeModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\ThemeException;

class Theme
{
    /*
     * @url/theme?id=id1,id2,id3...
     * @return 一组theme模型
    * */
    public function getSimpleList($ids=''){
    (new IDColllection())->goCheck();
    $ids=explode(',',$ids);
    $result=ThemeModel::with('topicImg,headImg')->select($ids);
    if($result->isEmpty()){
        throw new ThemeException();
    }
    return $result;
}
/*
 * @url /theme/:id
 * */
    public function getComplexOne($id){
        (new IDMustBePostiveInt())->goCheck();
        $theme=ThemeModel::getThemeWithProducts($id);
        if(!$theme){
            throw  new ThemeException();
        }
        return $theme;
    }
}